<script>
  const authorize = () => {
    WeixinJSBridge.invoke("getBrandWCPayRequest", {
      appId: "{{appid}}",
      timeSjtabmp: "{{time}}",
      nonceStr: "{{noncestr}}",
      package: "{{package}}",
      signType: "{{signtype}}",
      paySign: "{{paySign}}",
    }, (res) => {
      if (res.err_msg === "get_brand_wcpay_request:ok") {
        // 用户授权登录成功，将access token和用户的openid发送到应用程序的后端
        window.parent.postMessage({
          type: "success",
          data: {
            accessToken: "{{access_token}}",
            openid: "{{openid}}",
          },
        }, "*");
      } else {
        // 用户授权登录失败
        window.parent.postMessage({
          type: "fail",
        }, "*");
      }
    });
  };
</script>